package com.example.proxy.jdk;

import java.lang.reflect.Proxy;

/**
 * <p> JDK 动态代理测试 </p>
 *
 * @author Chris
 * @since 2022/11/29 10:15
 */
public class JdkDynamicProxyTest {

    public static void main(String[] args) {
        // 生成代理类文件 在根目录的同级目录，com下
        System.getProperties().put("sun.misc.ProxyGenerator.saveGeneratedFiles", "true");

        UserService02Impl userService = new UserService02Impl();
        Class<?> userServiceClass = userService.getClass();
        JdkDynamicProxy jdkDynamicProxy = new JdkDynamicProxy(userService);

        // 创建代理类对象
        UserService02 proxyInstance = (UserService02) Proxy.newProxyInstance(
                userServiceClass.getClassLoader(), userServiceClass.getInterfaces(), jdkDynamicProxy);
        proxyInstance.sayHello();
    }

}